home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / commontex / c / error < prev    next >
Encoding:
Text File  |  1988-04-18  |  10.3 KB  |  341 lines

  1. /*
  2.  *    Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
  3.  *    Copying of this file is granted according to the provisions 
  4.  *    specified in the file COPYING which must accompany this file.
  5.  */
  6.  
  7.  
  8. /*
  9.  *              error.c
  10.  */
  11.  
  12. #include "tex.h"
  13. #include "str.h"
  14. #include "tokenstack.h"
  15. #include "token.h"
  16. #include "eq.h"
  17. #include "io.h"
  18. #include "file.h"
  19. #include "print.h"
  20. #include "error.h"
  21.  
  22. int             OK_to_interrupt = TRUE;
  23. bool    deletions_allowed = TRUE;
  24. int             error_count;
  25. char*   help_line[6];
  26. int             help_ptr;
  27. int             history;
  28. int             interaction = ERROR_STOP_MODE;
  29. int             interrupt;
  30. int             old_setting;
  31. bool    use_err_help = FALSE;
  32.  
  33. jump_out ()
  34. {
  35.         close_files_and_terminate(FALSE);
  36. }
  37.  
  38. begin_diagnostic ()
  39. {
  40.         old_setting = selector;
  41.         if (tracing_online <= 0 && selector == TERM_AND_LOG) {
  42.                 decr(selector);
  43.                 if (history == SPOTLESS)
  44.                         history = WARNING_ISSUED;
  45.         }
  46. }
  47.  
  48. end_diagnostic (blank_line)
  49.         bool    blank_line;
  50. {
  51.         print_nl("");
  52.         if (blank_line) print_ln();
  53.         selector = old_setting;
  54. }
  55.  
  56. print_err (msg)
  57.         char*   msg;
  58. {
  59.         if (interaction == ERROR_STOP_MODE)     
  60.                 wake_up_terminal(); 
  61.         print_nl("! ");
  62.         print(msg);
  63. }
  64.  
  65. error ()
  66. {
  67.         ascii   c;
  68.         int             hx;
  69.         hword   s1;
  70.         hword   s2;
  71.         hword   s3;
  72.         val             s4;
  73.  
  74.         if (history < ERROR_MESSAGE_ISSUED)
  75.                 history = ERROR_MESSAGE_ISSUED;
  76.         print_char('.');
  77.         show_context();
  78.         if (interaction == ERROR_STOP_MODE) {
  79.                 loop {
  80.                         clear_for_error_prompt();
  81.                         prompt_input("? ");
  82.                         if (last == first)
  83.                                 return;
  84.                         c = buffer[first];
  85.                         if (c >= 'a')
  86.                                 c -= 'a' - 'A';
  87.                         switch (c)
  88.                         {
  89.                         case '1': case '2': case '3':
  90.                         case '4': case '5': case '6':
  91.                         case '7': case '8': case '9':
  92.                                 if (! deletions_allowed) continue;
  93.                                 s1 = cur_tok;
  94.                                 s2 = cur_cmd;
  95.                                 s3 = cur_chr;
  96.                                 s4 = align_state;
  97.                                 align_state = 1000000;
  98.                                 OK_to_interrupt = FALSE;
  99.                                 if (last > first + 1 &&
  100.                                         buffer[first + 1] >= '0' &&
  101.                                         buffer[first + 1] <= '9')
  102.                                         c = c * 10 + buffer[first + 1] - '0' * 11;
  103.                                 else c -= '0';
  104.                                 while (c > 0) {
  105.                                         get_token();
  106.                                         decr(c);
  107.                                 }
  108.                                 cur_tok = s1;
  109.                                 cur_cmd = s2;
  110.                                 cur_chr = s3;
  111.                                 align_state = s4;
  112.                                 OK_to_interrupt = TRUE;
  113.                                 help_delete_text();
  114.                                 show_context();
  115.                                 continue;
  116.                         
  117.                         case 'H':
  118.                                 if (use_err_help)  {
  119.                                         give_err_help();
  120.                                         use_err_help = FALSE;
  121.                                 } else {
  122.                                         if (help_ptr == 0)
  123.                                                 help_no_help();
  124.                                         else for (hx = 0; hx < help_ptr; incr(hx)) {
  125.                                                 print(help_line[hx]);
  126.                                                 print_ln();
  127.                                         }
  128.                                         help_help();
  129.                                 }
  130.                                 continue;
  131.                                 
  132.                         case 'I':
  133.                                 begin_file_reading();
  134.                                 if (last > first + 1) {
  135.                                         loc = first + 1;
  136.                                         buffer[first] = ' ';
  137.                                 } else {
  138.                                         prompt_input("insert>");
  139.                                         loc = first;
  140.                                 }
  141.                                 first = last;
  142.                                 limit = last - 1;
  143.                                 return;
  144.                         
  145.                         case 'Q':
  146.                         case 'R':
  147.                         case 'S':
  148.                                 error_count = 0;
  149.                                 interaction = BATCH_MODE + c - 'Q';
  150.                                 print("OK, entering ");
  151.                                 switch (c)
  152.                                 {
  153.                                 case 'Q':
  154.                                         print_esc("batchmode");
  155.                                         decr(selector);
  156.                                         break;
  157.                                 
  158.                                 case 'R':
  159.                                         print_esc("nonstopmode");
  160.                                         break;
  161.                                 
  162.                                 case 'S':
  163.                                         print_esc("scrollmode");
  164.                                         break;
  165.                                 }
  166.                                 print("...");
  167.                                 print_ln();
  168.                                 update_terminal();
  169.                                 return;
  170.                         
  171.                         case 'E':
  172.                                 if (base_ptr > 0)
  173.                                   call_editor (input_stack[base_ptr].name_field, line);/*DIFF*/
  174.                                 break;
  175.  
  176.                         case 'X':
  177.                                 interaction = SCROLL_MODE;
  178.                                 jump_out();
  179.                                 break;
  180.  
  181.                         default:
  182.                                 print_menu();
  183.                                 break;
  184.                         }
  185.                 }
  186.         }
  187.  
  188.         incr(error_count);
  189.         if (error_count == 100) {
  190.                 print_nl("(That makes 100 errors; please try again.)");
  191.                 history = FATAL_ERROR_STOP;
  192.                 jump_out();
  193.         }
  194.         if (interaction > BATCH_MODE)
  195.                 decr(selector);
  196.         if (use_err_help) {
  197.                 print_ln();
  198.                 give_err_help();
  199.         } else for (hx = 0; hx < help_ptr; incr(hx))
  200.                 print_nl(help_line[hx]);
  201.         help_ptr = 0;
  202.         print_ln();
  203.         if (interaction > BATCH_MODE)
  204.                 incr(selector);
  205.         print_ln();
  206. }
  207.  
  208. print_menu ()
  209. {
  210.         print("Type <return> to proceed, S to scroll future error messages,");
  211.         print_nl("R to run without stopping, Q to run quietly,");
  212.         print_nl("I to insert something, ");
  213.         if (base_ptr > 0)
  214.                 print("E to edit your file,");
  215.         if (deletions_allowed)
  216.                 print_nl("1 or ... or 9 to ignore the next 1 to 9 tokens of input");
  217. }
  218.  
  219. int_error (v)
  220.         val             v;
  221. {
  222.         print(" (");
  223.         print_val(v);
  224.         print_char(')');
  225.         error();
  226. }
  227.  
  228. normalize_selector ()
  229. {
  230.         if (job_name > 0)
  231.                 selector = TERM_AND_LOG;
  232.         else
  233.                 selector = TERM_ONLY;
  234.         if (job_name == 0)
  235.                 open_log_file();
  236.         if (interaction == BATCH_MODE)
  237.                 decr(selector);
  238. }
  239.  
  240. fatal_error (s)
  241.         char*   s;
  242. {
  243.         normalize_selector();
  244.         print_err("Emergency stop");
  245.         help1(s);
  246.         succumb();
  247. }
  248.  
  249. overflow (s, n)
  250.         char*   s;
  251.         int             n;
  252. {
  253.         normalize_selector();
  254.         print_err("TeX capacity exceeded, sorry [");
  255.         print(s);
  256.         print_char('=');
  257.         print_int(n);
  258.         print_char(']');
  259.         help_capacity();
  260.         succumb();
  261. }
  262.  
  263. confusion (s)
  264.         char*   s;
  265. {
  266.         normalize_selector();
  267.         if (history < ERROR_MESSAGE_ISSUED) {
  268.                 print_err("This can't happen (");
  269.                 print(s);
  270.                 print_char(')');
  271.                 help_broken();
  272.         } else {
  273.                 print_err("I can't go on meeting you like this");
  274.                 help_wounded();
  275.         }
  276.         succumb();
  277. }
  278.  
  279. pause_for_instructions ()
  280. {
  281.         if (OK_to_interrupt) {
  282.                 interaction = ERROR_STOP_MODE;
  283.                 if (selector == LOG_ONLY || selector == NO_PRINT)
  284.                         incr(selector);
  285.                 print_err("Interruption");
  286.                 help_interrupt();
  287.                 deletions_allowed = FALSE;
  288.                 error();
  289.                 deletions_allowed = TRUE;
  290.                 interrupt = 0;
  291.         }
  292. }
  293.  
  294. /*
  295.  *      Help text
  296.  */
  297.  
  298. help_delete_text () 
  299. {
  300.         help2("I have just deleted some text, as you asked.", 
  301.         "You can now delete more, or insert, or whatever.");
  302. }
  303.  
  304. help_no_help () 
  305. {
  306.         help2("Sorry, I don't know how to help in this situation.",
  307.         "Maybe you should try asking a human?");
  308. }
  309.  
  310. help_help () 
  311. {
  312.         help4("Sorry, I already gave what help I could...",
  313.         "Maybe you should try asking a human?", 
  314.         "An error might have occurred before I noticed any problems.",
  315.         "``If all else fails, read the instructions.''");
  316. }
  317.  
  318. help_capacity () 
  319. {
  320.         help2("If you really absolutely need more capacity,",
  321.         "you can ask a wizard to enlarge me.");
  322. }
  323.  
  324. help_broken () 
  325. {
  326.         help1("I'm broken. Please show this to someone who can fix can fix");
  327. }
  328.  
  329. help_wounded () 
  330. {
  331.         help2("One of your faux pas seems to have wounded me deeply...",
  332.         "in fact, I'm barely conscious. Please fix it and try again.");
  333. }
  334.  
  335. help_interrupt () 
  336. {
  337.         help3("You rang?",
  338.         "Try to insert some instructions for me (e.g., `I\\showlists),",
  339.         "unless you just want to quit by typing `X'.");
  340. }
  341.